package com.sdry.web.controller.jyy;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdry.model.jyy.MyWork;
import com.sdry.model.jyy.Solid;
import com.sdry.model.workplace.WorkCentrifugalDetails;
import com.sdry.model.zc.ZcMsSpotCheckDetailsEntity;
import com.sdry.service.jyy.MyWorkServise;
import com.sdry.utils.DateUtil;
import com.sdry.utils.ResponseUtil;

/**
 * @ClassName:    [MyWorkController]   
 * @Description:  [工位追溯]   
 * @Author:       [jyy]   
 * @CreateDate:   [2019年1月9日 下午6:10:54]    
 * @Version:      [v1.0]
 */
@Controller
@RequestMapping("/mywork")
public class MyWorkController {

	@Resource
	private MyWorkServise myWorkServise;
	
	@RequestMapping("/selectByTube")
	public void selectByTube(HttpServletResponse response,String tube) throws Exception {
		if(tube != null && tube != "") {
			List<MyWork> list = myWorkServise.selectByTube(tube);
			
			if(list.size() >0) {
				String starttime = list.get(0).getStarttime();
				String endtime = list.get(0).getEndtime();
				
				long diff = DateUtil.diff2(endtime,starttime);
				list.get(0).setDiff(diff+"");
			}
			JSONArray jsonArray = JSONArray.fromObject( list ); 
	        ResponseUtil.write(response, jsonArray);
		}else {
			ResponseUtil.write(response, "");
		}
	}
	
	/**
	 * 根据组件号查询离心三遍胶时间
	 * @param response
	 * @param tube
	 * @throws Exception 
	 */
	@RequestMapping("/selectLixinByTube")
	public void selectLixinByTube(HttpServletResponse response,String tube) throws Exception {
		List<WorkCentrifugalDetails> list = myWorkServise.selectLixinByTube(tube);
		JSONArray jsonArray = JSONArray.fromObject( list ); 
        ResponseUtil.write(response, jsonArray);
	}
	
	/**
	 * 根据组件条码查询膜丝检测信息
	 * @param response
	 * @param tube
	 * @throws Exception 
	 */
	@RequestMapping("/selectMs")
	public void selectMs(HttpServletResponse response,String tube,
			@RequestParam(value = "limit",required = false)int limit,
            @RequestParam(value = "page",required = false)int page) throws Exception {
		
		PageHelper.startPage(page, limit);
		List<ZcMsSpotCheckDetailsEntity> list = myWorkServise.selectMs(tube);
		PageInfo<ZcMsSpotCheckDetailsEntity> info = new PageInfo<ZcMsSpotCheckDetailsEntity>(list);
    	
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("msg", "");
        jsonObject.put("count", info.getTotal());
        jsonObject.put("data", info.getList());
        ResponseUtil.write(response, jsonObject);
	}
}
